Skip to content

Reland go_shim, replacing go runner by SDK's raw go - #54947

Open
rdesgroppes wants to merge 2 commits into
mainfrom
regis.desgroppes/reland-hermetic-go-shim
Open

Reland go_shim, replacing go runner by SDK's raw go#54947
rdesgroppes wants to merge 2 commits into
mainfrom
regis.desgroppes/reland-hermetic-go-shim

Conversation

@rdesgroppes

@rdesgroppes rdesgroppes commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Reland #54887, which #54925 reverted after it broke E2E jobs on main.

To prevent that from happening again, changes to bazel/rules/go_shim/**/* and internal/tools/** now trigger E2E tests unconditionally.

Recalling that PR: go_shim wraps a tool so that PATH lookups of go reach Bazel's hermetic SDK, and so that the tool runs from the current working directory rather than the runfiles tree, superseding rules_multitool's cwd().
It wraps gotestsum and go_mod_tidy_all, the latter dropping the $(rlocationpath @rules_go//go) resolution it had grown for itself and moving to its own package, where the shim taking over //:go_mod_tidy_all leaves its py_binary the plain name.

Changed on top of it:

  • PATH now holds the Go SDK's raw go (unwrapped), resolved through @rules_go//go:toolchain, in place of @rules_go//go (the runner),
  • the wrapper exports GOROOT and sets GOTOOLCHAIN=local itself rather than leaning on .bazelrc, and RUNFILES_DIR goes away with the runner that needed it.

Motivation

Unbreak dda inv test on hosts whose ambient go differs from the one go.work requires,
reported by @vitkyrka and followed up by @pgimalac and @hush-hush. #54107 routed it through bazel run //internal/tools:gotestsum, bringing gotestsum under .bazelrc's --run_env=GOTOOLCHAIN=local while it still resolved go through PATH, so every invocation failed with go.work requires go >= 1.26.5 and exporting GOTOOLCHAIN=auto did not help.

That fix then broke main, because @rules_go//go is a runner rather than a go: it assigns cmd.Dir from $BUILD_WORKING_DIRECTORY on every exec, discarding the directory its caller chose. gotest-custom chooses one per test package, so each prebuilt E2E test binary ran at the repository root and no longer found its fixtures, failing on compose/data, usmtest/test_tags.ps1, testdataprovision and checks/shared-library/files.

The SDK's go honors its caller, which is the whole of the difference.

Describe how you validated your changes

On Linux, a child go invoked from test/new-e2e under the shim reports that module's go.mod, where #54887 reported the repository root's.
Building a program importing net/http through the shim links, confirming the SDK's sources and tools are reachable.

The reported reproducer still holds: with a stub announcing itself as go 1.24.0 first in PATH, tools reach go1.26.5 and never the stub, and bazel run //:go_mod_tidy_all -- -diff exits 0 across every module.

Additional Notes

Prepending to PATH has no declarative spelling: RunEnvironmentInfo carries static strings only, a key given in both environment and inherited_environment resolves to the inherited value, and replacing PATH outright would hide sh, cc, git and whatever else the toolchain reaches for.
Hence a (thin) wrapper reading the environment at runtime.

The runfiles mirror go_bin_for_host, rules_go's own definition of a runnable go: the SDK binary plus its headers, libs, sources and tools.

install_gotestsum and its per-platform variants keep extracting the raw binary, the shim being runfiles-bound and those tools driving pre-built test binaries through --raw-command, never resolving go.

@rdesgroppes rdesgroppes added changelog/no-changelog No changelog entry needed qa/no-code-change No code change in Agent code requiring validation labels Aug 17, 2026
@github-actions github-actions Bot added the medium review PR review might take time label Aug 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@rdesgroppes rdesgroppes changed the title Reland go_shim, taking go from the SDK not the launcher Reland go_shim, taking go from the SDK (not the launcher) Aug 17, 2026
@dd-octo-sts

dd-octo-sts Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Gitlab CI Configuration Changes

⚠️ Diff too large to display on Github.

Changes Summary

Removed Modified Added Renamed
0 139 0 0

ℹ️ Diff available in the job log.

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 52.43% (+0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bb721ce | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Files inventory check summary

File checks results against ancestor 62e3f01d:

Results for datadog-agent_7.84.0~devel.git.231.bb721ce.pipeline.131295372-1_amd64.deb:

No change detected

Results for datadog-iot-agent_7.84.0~devel.git.231.bb721ce.pipeline.131295372-1_amd64.deb:

No change detected

@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/reland-hermetic-go-shim branch from 560772e to 730749e Compare August 17, 2026 09:14
@rdesgroppes rdesgroppes changed the title Reland go_shim, taking go from the SDK (not the launcher) Reland go_shim, replacing go runner by SDK's raw go Aug 17, 2026
@rdesgroppes
rdesgroppes marked this pull request as ready for review August 17, 2026 09:17
@rdesgroppes
rdesgroppes requested review from a team as code owners August 17, 2026 09:17
@dd-octo-sts

dd-octo-sts Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 62e3f01
📊 Static Quality Gates Dashboard
🔗 SQG Job

33 successful checks with minimal change (< 2 KiB)
Quality gate Current Size
agent_deb_amd64 760.225 MiB
agent_deb_amd64_fips 713.082 MiB
agent_heroku_amd64 312.557 MiB
agent_msi 644.206 MiB
agent_rpm_amd64 760.209 MiB
agent_rpm_amd64_fips 713.066 MiB
agent_rpm_arm64 735.966 MiB
agent_rpm_arm64_fips 692.157 MiB
agent_suse_amd64 760.209 MiB
agent_suse_amd64_fips 713.066 MiB
agent_suse_arm64 735.966 MiB
agent_suse_arm64_fips 692.157 MiB
docker_agent_amd64 818.841 MiB
docker_agent_arm64 819.642 MiB
docker_agent_jmx_amd64 1009.739 MiB
docker_agent_jmx_arm64 999.192 MiB
docker_cluster_agent_amd64 210.475 MiB
docker_cluster_agent_arm64 223.456 MiB
docker_cws_instrumentation_amd64 7.439 MiB
docker_cws_instrumentation_arm64 6.877 MiB
docker_dogstatsd_amd64 39.482 MiB
docker_dogstatsd_arm64 37.560 MiB
docker_host_profiler_amd64 305.814 MiB
docker_host_profiler_arm64 317.125 MiB
dogstatsd_deb_amd64 30.224 MiB
dogstatsd_deb_arm64 28.247 MiB
dogstatsd_rpm_amd64 30.224 MiB
dogstatsd_suse_amd64 30.224 MiB
iot_agent_deb_amd64 46.479 MiB
iot_agent_deb_arm64 43.131 MiB
iot_agent_deb_armhf 43.914 MiB
iot_agent_rpm_amd64 46.480 MiB
iot_agent_suse_amd64 46.478 MiB

@chouetz chouetz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some more paths?

Comment thread .gitlab-ci.yml
- changes:
paths:
- .gitlab/test/e2e/e2e.yml
- internal/tools/**/* # Go tools: gotestsum, etc. (incident-59251/59255/59256/59257/59258)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the shim implementation in E2E change rules

When a follow-up changes bazel/rules/go_shim/defs.bzl or either wrapper template without also touching internal/tools, this rule will not schedule the E2E jobs, even though tasks/gotest.py runs E2E tests through the shimmed //internal/tools:gotestsum target. Since the newly introduced shim code controls the working-directory behavior that previously broke E2E, add bazel/rules/go_shim/**/* to this change set so those runtime-only regressions are exercised before reaching main.

Useful? React with 👍 / 👎.

I suppose this remark is valuable

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 17, 2026

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Job ID: cab01787-06f0-44f8-a6bc-ebd4c3d64be7

Baseline: 0557b36
Comparison: bb721ce
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_private_action_runner memory utilization +0.45 [+0.33, +0.57] 1 Logs bounds checks dashboard
quality_gate_security_idle memory utilization +0.20 [+0.10, +0.31] 1 Logs bounds checks dashboard
quality_gate_security_mean_fs_load memory utilization +0.03 [-0.05, +0.10] 1 Logs bounds checks dashboard
quality_gate_logs % cpu utilization +0.02 [-0.87, +0.91] 1 Logs bounds checks dashboard
quality_gate_idle_all_features memory utilization +0.01 [-0.03, +0.05] 1 Logs bounds checks dashboard
quality_gate_security_no_fs_load memory utilization -0.25 [-0.40, -0.11] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization -0.43 [-0.55, -0.31] 1 Logs bounds checks dashboard
quality_gate_metrics_logs memory utilization -0.64 [-0.89, -0.40] 1 Logs bounds checks dashboard

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
quality_gate_idle intake_connections 10/10 4 = 4 bounds checks dashboard
quality_gate_idle memory_usage 10/10 174.58MiB ≤ 178MiB bounds checks dashboard
quality_gate_idle total_bytes_received 10/10 741.62KiB ≤ 819.20KiB bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 4 = 4 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 517.81MiB ≤ 538MiB bounds checks dashboard
quality_gate_idle_all_features total_bytes_received 10/10 1.14MiB ≤ 1.25MiB bounds checks dashboard
quality_gate_logs intake_connections 10/10 18 ≤ 40 bounds checks dashboard
quality_gate_logs memory_usage 10/10 206.21MiB ≤ 229MiB bounds checks dashboard
quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_logs total_bytes_received 10/10 264.18MiB ≤ 292MiB bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 377.79 ≤ 2000 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 19 ≤ 40 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 413.85MiB ≤ 439MiB bounds checks dashboard
quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_metrics_logs total_bytes_received 10/10 0.94GiB ≤ 1.04GiB bounds checks dashboard
quality_gate_private_action_runner memory_usage 10/10 72.20MiB ≤ 76MiB bounds checks dashboard
quality_gate_security_idle cpu_usage 10/10 26.98 ≤ 100 bounds checks dashboard
quality_gate_security_idle memory_usage 10/10 322.45MiB ≤ 335MiB bounds checks dashboard
quality_gate_security_mean_fs_load cpu_usage 10/10 60.06 ≤ 200 bounds checks dashboard
quality_gate_security_mean_fs_load memory_usage 10/10 302.87MiB ≤ 314MiB bounds checks dashboard
quality_gate_security_no_fs_load cpu_usage 10/10 19.87 ≤ 100 bounds checks dashboard
quality_gate_security_no_fs_load memory_usage 10/10 310.39MiB ≤ 343MiB bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_private_action_runner, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.

### What does this PR do?
Relands #54887, which #54925 reverted after it broke E2E jobs on `main`.

Recalling that PR: `go_shim` wraps a tool so that `PATH` lookups of `go`
reach Bazel's hermetic SDK, and so that the tool runs from the current
working directory rather than the runfiles tree, superseding
`rules_multitool`'s `cwd()`.
It wraps `gotestsum` and `go_mod_tidy_all`, the latter dropping the
`$(rlocationpath @rules_go//go)` resolution it had grown for itself and
moving to its own package, where the shim taking over
`//:go_mod_tidy_all` leaves its `py_binary` the plain name.

Changed on top of it: `PATH` now holds the Go SDK's own `go`, resolved
through `@rules_go//go:toolchain`, in place of `@rules_go//go`.
The wrapper exports `GOROOT` and sets `GOTOOLCHAIN=local` itself rather
than leaning on `.bazelrc`, and `RUNFILES_DIR` goes away with the
launcher that needed it.

### Motivation
Unbreak `dda inv test` on hosts whose ambient `go` differs from the one
`go.work` requires,
[reported](https://dd.slack.com/archives/C06PBHLD4DQ/p1786618886362859)
by @vitkyrka and followed up by @pgimalac and @hush-hush.
#54107 routed it through `bazel run //internal/tools:gotestsum`,
bringing `gotestsum` under `.bazelrc`'s `--run_env=GOTOOLCHAIN=local`
while it still resolved `go` through `PATH`, so every invocation failed
with `go.work requires go >= 1.26.5` and exporting `GOTOOLCHAIN=auto`
did not help.

That fix then broke `main`, because `@rules_go//go` is a launcher rather
than a `go`: it assigns `cmd.Dir` from `$BUILD_WORKING_DIRECTORY` on
every exec, discarding the directory its caller chose.
`gotest-custom` chooses one per test package, so each prebuilt E2E test
binary ran at the repository root and no longer found its fixtures,
failing on `compose/data`, `usmtest/test_tags.ps1`, `testdataprovision`
and `checks/shared-library/files`.
The SDK's `go` honors its caller, which is the whole of the difference.

### Describe how you validated your changes
On Linux, a child `go` invoked from `test/new-e2e` under the shim
reports that module's `go.mod`, where #54887 reported the repository
root's.
Building a program importing `net/http` through the shim links,
confirming the SDK's sources and tools are reachable.

The reported reproducer still holds: with a stub announcing itself as go
1.24.0 first in `PATH`, tools reach go1.26.5 and never the stub, and
`bazel run //:go_mod_tidy_all -- -diff` exits 0 across every module.

### Additional Notes
Prepending to `PATH` has no declarative spelling: `RunEnvironmentInfo`
carries static strings only, a key given in both `environment` and
`inherited_environment` resolves to the inherited value, and replacing
`PATH` outright would hide `sh`, `cc`, `git` and whatever else the
toolchain reaches for.
Hence a (thin) wrapper reading the environment at runtime.

The runfiles mirror `go_bin_for_host`, rules_go's own definition of a
runnable `go`: the SDK binary plus its headers, libs, sources and tools.

`install_gotestsum` and its per-platform variants keep extracting the
raw binary, the shim being runfiles-bound and those tools driving
pre-built test binaries through `--raw-command`, never resolving `go`.
@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/reland-hermetic-go-shim branch from 730749e to bb721ce Compare August 17, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed internal Identify a non-fork PR medium review PR review might take time qa/no-code-change No code change in Agent code requiring validation team/agent-build team/agent-devx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants